<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.0.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Gemini","version":"8.7.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>
<meta name="description" content="预览链接">
<meta property="og:type" content="article">
<meta property="og:title" content="大屏可视化项">
<meta property="og:url" content="http://example.com/2022/02/05/08/index.html">
<meta property="og:site_name" content="Xiaolong&#39;s Blog">
<meta property="og:description" content="预览链接">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-16-58.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/abxl1-8g4hn.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/aw0qr-ewt2l.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/ajxvu-1zcut.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/2022-2-5-dfa54%20(1).gif">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/%E5%9B%BE%E7%89%871-2022.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/%E5%9B%BE%E7%89%87-2022-2-2.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-03-20.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-33-07.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-43-56.png">
<meta property="article:published_time" content="2022-02-05T11:33:08.000Z">
<meta property="article:modified_time" content="2023-03-07T13:31:42.092Z">
<meta property="article:author" content="Xiaolong">
<meta property="article:tag" content="react">
<meta property="article:tag" content="rem">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-16-58.png">


<link rel="canonical" href="http://example.com/2022/02/05/08/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"en","comments":true,"permalink":"http://example.com/2022/02/05/08/","path":"2022/02/05/08/","title":"大屏可视化项"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>大屏可视化项 | Xiaolong's Blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Xiaolong's Blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="Searching..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A1%B9%E7%9B%AE%E6%8F%8F%E8%BF%B0"><span class="nav-number">1.</span> <span class="nav-text">项目描述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%80%82%E9%85%8D%E5%B1%8F%E5%B9%95"><span class="nav-number">2.</span> <span class="nav-text">适配屏幕</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%9A-rem"><span class="nav-number">2.1.</span> <span class="nav-text">解决方案： rem</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#rem-%E8%AE%A1%E7%AE%97%E5%85%AC%E5%BC%8F"><span class="nav-number">2.2.</span> <span class="nav-text">rem 计算公式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#element-%E7%94%A8-rem"><span class="nav-number">2.3.</span> <span class="nav-text">element 用 rem</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8-grid-%E5%B8%83%E5%B1%80"><span class="nav-number">3.</span> <span class="nav-text">使用 grid 布局</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8-Echart"><span class="nav-number">4.</span> <span class="nav-text">使用 Echart</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%94%BB%E5%9C%B0%E5%9B%BE"><span class="nav-number">5.</span> <span class="nav-text">画地图</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Xiaolong"
      src="/images/lion.jpg">
  <p class="site-author-name" itemprop="name">Xiaolong</p>
  <div class="site-description" itemprop="description">Never stop learning</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">45</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/drwna" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;drwna" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



          </div>
        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="Back to top">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/Drwna" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="en">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/02/05/08/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/lion.jpg">
      <meta itemprop="name" content="Xiaolong">
      <meta itemprop="description" content="Never stop learning">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Xiaolong's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          大屏可视化项
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2022-02-05 19:33:08" itemprop="dateCreated datePublished" datetime="2022-02-05T19:33:08+08:00">2022-02-05</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p><a target="_blank" rel="noopener" href="https://draganet.gitee.io/bigscreen-website/#/">预览链接</a></p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-16-58.png" alt="Snipaste_2022-02-06_00-16-58" width="800px"></center>

<span id="more"></span>



<h2 id="项目描述"><a href="#项目描述" class="headerlink" title="项目描述"></a>项目描述</h2><p>技术栈：React + ReactRouter + Echart + Typescript </p>
<p>这个项目是我在学习适配大屏与 Echart 时，仿的开源项目做的。</p>
<p>页面布局使用了 Grid 和 Flex 布局，使用 rem 动态记算适配不同尺寸的屏幕。</p>
<p>项目中包含的图例有柱形图、折线图、饼图、地图和表格等。</p>
<p>通过这个项目，我掌握了大屏可视化项目的制作技巧。</p>
<h2 id="适配屏幕"><a href="#适配屏幕" class="headerlink" title="适配屏幕"></a>适配屏幕</h2><p>市面上大部分的显示器几乎都是<code>16：9</code>的尺寸，也就是<code>1920 * 1080</code>的分辨率。</p>
<p><strong>理想中的效果：</strong></p>
<ul>
<li><p>当屏幕的尺寸比例刚好是16：9时，页面能刚好全屏展示，内容占满显示器</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/abxl1-8g4hn.png" alt="abxl1-8g4hn" width="400px"></center></li>
</ul>
<ul>
<li><p>当屏幕的尺寸比例小于16：9时，页面上下留白，左右占满并上下居中，显示比例保持16：9</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/aw0qr-ewt2l.png" alt="aw0qr-ewt2l" width="400px"></center></li>
</ul>
<ul>
<li><p>当屏幕尺寸比例大于16：9时，页面左右留白，上下占满并居中，显示比例保持16：9</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/ajxvu-1zcut.png" alt="ajxvu-1zcut" width="400px"></center></li>
</ul>
<blockquote>
<p>当屏幕大小改变时，动态计算中间内容的显示比例大小，保证内容一直保持16：9</p>
</blockquote>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/2022-2-5-dfa54%20(1).gif" alt="2022-2-5-dfa54 (1)" width="800px"></center>





<h3 id="解决方案：-rem"><a href="#解决方案：-rem" class="headerlink" title="解决方案： rem"></a>解决方案： rem</h3><p><code>rem(font size of the root element)</code></p>
<p>是 css3 中新增的一个大小单位，即相对于根元素 font-size 值的大小。</p>
<p>思路就是动态的计算出页面的 fontsize 从而改变 rem 的大小。</p>
<h3 id="rem-计算公式"><a href="#rem-计算公式" class="headerlink" title="rem 计算公式"></a>rem 计算公式</h3><center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/%E5%9B%BE%E7%89%871-2022.png" alt="图片1-2022" width="400px"></center>

<p><strong>W<sub>p</sub> 为页面有效宽度，H<sub>p</sub> 为页面有效宽度</strong></p>
<p><strong>页面左右居中，上下居中，四周留白即可</strong></p>
<p><strong>然后在 head 里用 JS　设置　１rem = W<sub>p</sub> / 100</strong></p>
<h3 id="element-用-rem"><a href="#element-用-rem" class="headerlink" title="element 用 rem"></a>element 用 rem</h3><center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/%E5%9B%BE%E7%89%87-2022-2-2.png" alt="图片-2022-2-2" width="800px"></center>

<p>假设某 div 在设计稿中长 100px，设计稿宽度 1920px</p>
<p>那么该 div 在页面中长为 100/1920 * 100rem</p>
<p>最后可以写一个 px() 函数来计算 100px 对应的 rem</p>
<p><strong>写个 scss 函数</strong></p>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@function</span> px(<span class="variable">$n</span>) &#123;</span><br><span class="line">  <span class="keyword">@return</span> <span class="variable">$n</span> /  <span class="number">2420</span> * <span class="number">100rem</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<p>代码：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;zh&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">content</span>=<span class="string">&quot;width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>大屏可视化项目<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">const</span> clientWidth = <span class="variable language_">document</span>.<span class="property">documentElement</span>.<span class="property">clientWidth</span></span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">const</span> clientHeight = <span class="variable language_">document</span>.<span class="property">documentElement</span>.<span class="property">clientHeight</span></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">window</span>.<span class="property">pageWidth</span> = clientWidth / clientHeight &gt; <span class="number">16</span> / <span class="number">9</span> ? clientHeight * (<span class="number">16</span> / <span class="number">9</span>) : clientWidth</span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">const</span> pageHeight = pageWidth / (<span class="number">16</span> / <span class="number">9</span>)</span></span><br><span class="line"><span class="language-javascript">    <span class="comment">// 设置一个 rem</span></span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">const</span> string = <span class="string">`</span></span></span><br><span class="line"><span class="string"><span class="language-javascript">    &lt;style&gt;</span></span></span><br><span class="line"><span class="string"><span class="language-javascript">     html&#123;</span></span></span><br><span class="line"><span class="string"><span class="language-javascript">      font-size: <span class="subst">$&#123;pageWidth / <span class="number">100</span>&#125;</span>px</span></span></span><br><span class="line"><span class="string"><span class="language-javascript">     &#125;</span></span></span><br><span class="line"><span class="string"><span class="language-javascript">    &lt;/style&gt;`</span></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">document</span>.<span class="title function_">write</span>(string)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;root&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="comment">// root.style.width = pageWidth + &#x27;px&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    root.<span class="property">style</span>.<span class="property">height</span> = pageHeight + <span class="string">&#x27;px&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    root.<span class="property">style</span>.<span class="property">marginTop</span> = (clientHeight - pageHeight) / <span class="number">2</span> + <span class="string">&#x27;px&#x27;</span></span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;module&quot;</span> <span class="attr">src</span>=<span class="string">&quot;/src/main.tsx&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>





<h2 id="使用-grid-布局"><a href="#使用-grid-布局" class="headerlink" title="使用 grid 布局"></a>使用 grid 布局</h2><p><a target="_blank" rel="noopener" href="https://drwna.github.io/2021/07/09/28/?highlight=grid#grid-template-areas">grid-template-areas</a></p>
<p>效果图</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-03-20.png" alt="Snipaste_2022-02-06_00-03-20" width="800px"></center>

<p>主要代码：</p>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.home</span> &#123;</span><br><span class="line">  &gt; <span class="selector-tag">main</span> &#123;</span><br><span class="line">    <span class="attribute">display</span>: grid;</span><br><span class="line">    <span class="attribute">grid-template</span>:</span><br><span class="line">    <span class="string">&#x27;box1 box2 box4 box5&#x27;</span> <span class="number">755</span>fr</span><br><span class="line">    <span class="string">&#x27;box3 box3 box4 box5&#x27;</span> <span class="number">363</span>fr / <span class="number">366</span>fr <span class="number">361</span>fr <span class="number">811</span>fr <span class="number">747</span>fr;</span><br><span class="line">    &gt; <span class="selector-class">.section1</span> &#123;</span><br><span class="line">      <span class="attribute">grid-area</span>: box1;</span><br><span class="line">    &#125;</span><br><span class="line">    &gt; <span class="selector-class">.section2</span> &#123;</span><br><span class="line">      <span class="attribute">grid-area</span>: box2;</span><br><span class="line">    &#125;</span><br><span class="line">    &gt; <span class="selector-class">.section3</span> &#123;</span><br><span class="line">      <span class="attribute">grid-area</span>: box3;</span><br><span class="line">    &#125;</span><br><span class="line">    &gt; <span class="selector-class">.section4</span> &#123;</span><br><span class="line">      <span class="attribute">grid-area</span>: box4;</span><br><span class="line">    &#125;</span><br><span class="line">    &gt; <span class="selector-class">.section5</span> &#123;</span><br><span class="line">      <span class="attribute">grid-area</span>: box5;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="使用-Echart"><a href="#使用-Echart" class="headerlink" title="使用 Echart"></a>使用 Echart</h2><p>安装 <code>yarn add -D echarts</code></p>
<p>引入 <code>import * as echarts from &#39;echarts&#39;;</code></p>
<p>chart1 效果图：</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-33-07.png" alt="Snipaste_2022-02-06_00-33-07" width="500px"></center>

<p>chart1 代码</p>
<figure class="highlight tsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">React</span>, &#123;useEffect, useRef&#125; <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> * <span class="keyword">as</span> echarts <span class="keyword">from</span> <span class="string">&#x27;echarts&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="title function_">Chart1</span> = (<span class="params"></span>) =&gt; &#123;</span><br><span class="line">  <span class="keyword">const</span> <span class="title function_">px</span> = (<span class="params">n</span>) =&gt; n / <span class="number">2420</span> * (<span class="variable language_">window</span> <span class="keyword">as</span> <span class="built_in">any</span>).<span class="property">pageWidth</span>;</span><br><span class="line">  <span class="keyword">const</span> divRef = <span class="title function_">useRef</span>(<span class="literal">null</span>);</span><br><span class="line">  <span class="title function_">useEffect</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> myChart = echarts.<span class="title function_">init</span>(divRef.<span class="property">current</span>);</span><br><span class="line">      </span><br><span class="line">    myChart.<span class="title function_">setOption</span>(&#123;</span><br><span class="line">      <span class="attr">title</span>: &#123;<span class="attr">show</span>: <span class="literal">false</span>&#125;,</span><br><span class="line">      <span class="attr">legend</span>: &#123;<span class="attr">show</span>: <span class="literal">false</span>&#125;,</span><br><span class="line">      <span class="attr">xAxis</span>: &#123;</span><br><span class="line">        <span class="attr">data</span>: [<span class="string">&#x27;城关区&#x27;</span>, <span class="string">&#x27;七里河区&#x27;</span>, <span class="string">&#x27;西固区&#x27;</span>, <span class="string">&#x27;安宁区&#x27;</span>, <span class="string">&#x27;红古区&#x27;</span>, <span class="string">&#x27;永登区&#x27;</span>, <span class="string">&#x27;皋兰区&#x27;</span>, <span class="string">&#x27;榆中区&#x27;</span>, <span class="string">&#x27;兰州新区&#x27;</span>],</span><br><span class="line">        <span class="attr">axisTick</span>: &#123;<span class="attr">show</span>: <span class="literal">false</span>&#125;,</span><br><span class="line">        <span class="attr">axisLabel</span>: &#123;</span><br><span class="line">          <span class="attr">fontSize</span>: <span class="title function_">px</span>(<span class="number">12</span>),</span><br><span class="line">          <span class="attr">interval</span>: <span class="number">0</span>,</span><br><span class="line">          <span class="title function_">formatter</span>(<span class="params">val</span>) &#123;</span><br><span class="line">            <span class="keyword">if</span> (val.<span class="property">length</span> &gt; <span class="number">2</span>) &#123;</span><br><span class="line">              <span class="keyword">const</span> array = val.<span class="title function_">split</span>(<span class="string">&#x27;&#x27;</span>);</span><br><span class="line">              array.<span class="title function_">splice</span>(<span class="number">2</span>, <span class="number">0</span>, <span class="string">&#x27;\n&#x27;</span>);</span><br><span class="line">              <span class="keyword">return</span> array.<span class="title function_">join</span>(<span class="string">&#x27;&#x27;</span>);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">              <span class="keyword">return</span> val;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">yAxis</span>: &#123;</span><br><span class="line">        <span class="attr">splitLine</span>: &#123;<span class="attr">show</span>: <span class="literal">false</span>&#125;,</span><br><span class="line">        <span class="attr">axisLine</span>: &#123;<span class="attr">lineStyle</span>: &#123;<span class="attr">color</span>: <span class="string">&#x27;#686a75&#x27;</span>&#125;&#125;,</span><br><span class="line">        <span class="attr">axisLabel</span>: &#123;</span><br><span class="line">          <span class="attr">fontSize</span>: <span class="title function_">px</span>(<span class="number">12</span>)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">grid</span>: &#123;</span><br><span class="line">        <span class="attr">x</span>: <span class="title function_">px</span>(<span class="number">40</span>),</span><br><span class="line">        <span class="attr">y</span>: <span class="title function_">px</span>(<span class="number">40</span>),</span><br><span class="line">        <span class="attr">x2</span>: <span class="title function_">px</span>(<span class="number">40</span>),</span><br><span class="line">        <span class="attr">y2</span>: <span class="title function_">px</span>(<span class="number">40</span>)</span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">series</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">name</span>: <span class="string">&#x27;人数&#x27;</span>,</span><br><span class="line">          <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">          <span class="attr">data</span>: [<span class="number">5</span>, <span class="number">20</span>, <span class="number">24</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">32</span>, <span class="number">8</span>, <span class="number">12</span>, <span class="number">19</span>, <span class="number">6</span>],</span><br><span class="line">        &#125;,</span><br><span class="line">      ]</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;, []);</span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    <span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">className</span>=<span class="string">&quot;bordered 管辖统计&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">h2</span>&gt;</span>案发派出所管辖统计<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">ref</span>=<span class="string">&#123;divRef&#125;</span> <span class="attr">className</span>=<span class="string">&quot;chart&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">  );</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">export</span> &#123;<span class="title class_">Chart1</span>&#125;;</span><br></pre></td></tr></table></figure>



<h2 id="画地图"><a href="#画地图" class="headerlink" title="画地图"></a>画地图</h2><p>需要引入 <a target="_blank" rel="noopener" href="https://github.com/yezongyang/china-geojson">china.json</a></p>
<figure class="highlight tsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> china <span class="keyword">from</span> <span class="string">&#x27;../geo/china.json&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p>echart 中注册一个地图：</p>
<center><img src="https://cdn.jsdelivr.net/gh/Drwna/image//images/Snipaste_2022-02-06_00-43-56.png" alt="Snipaste_2022-02-06_00-43-56" width="600px"></center>



<blockquote>
<p>参考 <a target="_blank" rel="noopener" href="https://juejin.cn/post/6972416642600927246">https://juejin.cn/post/6972416642600927246</a></p>
</blockquote>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/react/" rel="tag"><i class="fa fa-tag"></i> react</a>
              <a href="/tags/rem/" rel="tag"><i class="fa fa-tag"></i> rem</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2022/01/28/27/" rel="prev" title="随手记 React 总结">
                  <i class="fa fa-chevron-left"></i> 随手记 React 总结
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2022/02/12/20/" rel="next" title="wheel ui">
                  wheel ui <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2021 – 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Xiaolong</span>
</div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/third-party/search/local-search.js"></script>




  





</body>
</html>
